import { Modal } from "antd";
import clsx from "clsx";
let messageFlag = 0;
let message={
  info: function ({ title = "提示", content = "未知错误", okText = "我知道了", width = 500, onOk, afterClose, icon } = {}) {
    if(messageFlag > 0){//如果弹出框标记>0，不要出现新的提示，防止出现大量提示信息
      return;
    }
    messageFlag += 1;// <0 则+1，在上一个message关闭前，不会再响应新的提示
    return Modal.info({
      title: title,
      icon: icon,
      content: <div className="mysoft-message-content" dangerouslySetInnerHTML={{__html: content}}></div>,
      okText: okText,
      centered: true,
      className: "info-modal",
      width: width,
      onOk: (close) => {
        onOk?.();
        close();
      },
      afterClose: () => {
        messageFlag = 0;//关闭message后重置为0，可继续响应提示
        afterClose?.();
      },
    });

  },
  confirm: function({
    title="提示",
    cancelText="取消",
    width = 500,
    okType,//确认按钮类型	
    okText="确定",
    onOk,//点击确定回调，参数为关闭函数，返回 promise 时 resolve 后自动关闭	
    onCancel,//取消回调，参数为关闭函数，返回 promise 时 resolve 后自动关闭	
    afterClose,
    content="未知错误"
  }){
    return Modal.confirm({
      autoFocusButton: null,//指定自动获得焦点的按钮
      content: <div className={clsx("h-44 overflow-auto flex items-center", content.length <= 25 && "justify-center")}>{content}</div>,
      wrapClassName: "myConfirm",
      title: title,
      cancelText: cancelText,
      okType: okType,
      okText: okText,
      centered:true,
      width: width,
      keyboard: false,
      onOk:function(close){
        onOk?.()
        close();
      },
      onCancel:function(close){
        onCancel?.();
        close();
      },
      afterClose: () => {
        afterClose?.();
      },
    });
  },
  confirmSM: function({
    title="提示",
    cancelText="取消",
    width = 400,
    onOk,
    afterClose,
    content="未知错误"
  }){
    return Modal.confirm({
      content: <div className={clsx(" text-base h-[60px] overflow-auto flex items-center", content.length <= 25 && "justify-center")}>{content}</div>,
      wrapClassName:"myConfirm",
      title: title,
      cancelText: cancelText,
      centered:true,
      width: width,
      keyboard: false,
      onOk:function(close){
        onOk?.()
        close();
      },
      afterClose: () => {
        afterClose?.();
      },
    });
  }
};

export default message